package com.livi.security.controller.sys;

import com.livi.security.model.commom.BaseResponse;
import com.livi.security.model.sys.SysUser;
import com.livi.security.service.sys.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author Livi Luo
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping(value = "get", method = RequestMethod.GET)
    public BaseResponse get(Integer userId) {
        return userService.get(userId);
    }

    @RequestMapping(value = "list", method = RequestMethod.GET)
    public BaseResponse getList() {
        return userService.getList();
    }

    @RequestMapping(value = "add", method = RequestMethod.POST)
    public BaseResponse add(@RequestBody SysUser record, Authentication authentication) {
        Integer currentUser = Integer.parseInt(authentication.getName());
        return userService.add(record, currentUser);
    }

    @RequestMapping(value = "update", method = RequestMethod.PUT)
    public BaseResponse update(@RequestBody SysUser record, Authentication authentication) {
        Integer currentUser = Integer.parseInt(authentication.getName());
        return userService.update(record, currentUser);
    }

    @RequestMapping(value = "delete", method = RequestMethod.DELETE)
    public BaseResponse delete(Integer userId) {
        return userService.delete(userId);
    }

}
